import { axios } from '@/utils/request'

const api = {
  user: '/user',
  role: '/role',
  service: '/service',
  permission: '/permission',
  permissionNoPager: '/permission/no-pager',
  orgTree: '/org/tree'
}

export default api

export function getUserList (parameter) {
  return axios({
    url: api.user,
    method: 'get',
    params: parameter
  })
}

export function getRoleList (parameter) {
  return axios({
    url: api.role,
    method: 'get',
    params: parameter
  })
}

export function getServiceList (parameter) {
  return axios({
    url: api.service,
    method: 'get',
    params: parameter
  })
}

export function getPermissions (parameter) {
  return axios({
    url: api.permissionNoPager,
    method: 'get',
    params: parameter
  })
}

export function fetchCategoryList (parameter) {
  return axios({
    url: '/inventory/product/category/list',
    method: 'post',
    data: parameter
  })
}
export function fetchBrandsList (parameter) {
  return axios({
    url: '/inventory/product/brands/list',
    method: 'post',
    data: parameter
  })
}
export function fetchAttrList (parameter) {
  return axios({
    url: '/inventory/product/attr/list',
    method: 'post',
    data: parameter
  })
}
export function fetchTagList (parameter) {
  return axios({
    url: '/inventory/product/label/list',
    method: 'post',
    data: parameter
  })
}
export function delTag (parameter) {
  return axios({
    url: '/inventory/product/label/delete',
    method: 'post',
    data: parameter
  })
}
export function delBrand (parameter) {
  return axios({
    url: '/inventory/product/brands/delete',
    method: 'post',
    data: parameter
  })
}
export function addTag (parameter) {
  return axios({
    url: '/inventory/product/label/add',
    method: 'post',
    data: parameter
  })
}
export function editBrand (parameter) {
  return axios({
    url: '/inventory/product/brands/edit',
    method: 'post',
    data: parameter
  })
}
export function editBrandStatus (parameter) {
  return axios({
    url: '/inventory/product/brands/update/status',
    method: 'post',
    data: parameter
  })
}
export function fetchBrandInfo (parameter) {
  return axios({
    url: '/inventory/product/brands/info',
    method: 'post',
    data: parameter
  })
}
export function addAttr (parameter) {
  return axios({
    url: '/inventory/product/attr/add',
    method: 'post',
    data: parameter
  })
}
export function updateAttr (parameter) {
  return axios({
    url: '/inventory/product/attr/update',
    method: 'post',
    data: parameter
  })
}
export function editTag (parameter) {
  return axios({
    url: '/inventory/product/label/edit',
    method: 'post',
    data: parameter
  })
}
export function addBrands (parameter) {
  return axios({
    url: '/inventory/product/brands/add',
    method: 'post',
    data: parameter
  })
}
export function addCategory (parameter) {
  return axios({
    url: '/inventory/product/category/add',
    method: 'post',
    data: parameter
  })
}
export function editCategory (parameter) {
  return axios({
    url: '/inventory/product/category/edit',
    method: 'post',
    data: parameter
  })
}
export function getStoreList (parameter) {
  return axios({
    url: '/merchant/admin/store/grade-list',
    method: 'post',
    data: { ...parameter, getStoreList: 1 }
  })
}
export function delCategory (parameter) {
  return axios({
    url: '/inventory/product/category/delete',
    method: 'post',
    data: parameter
  })
}
export function getOrgTree (parameter) {
  return axios({
    url: api.orgTree,
    method: 'get',
    params: parameter
  })
}

// id == 0 add     post
// id != 0 update  put
export function saveService (parameter) {
  return axios({
    url: api.service,
    method: parameter.id === 0 ? 'post' : 'put',
    data: parameter
  })
}
